export const formatTime = (date: Date) => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return (
    [year, month, day].map(formatNumber).join('/') +
    ' ' +
    [hour, minute, second].map(formatNumber).join(':')
  )
}

export const formatNumber = (n: number) => {
  const s = n.toString()
  return s[1] ? s : '0' + s
}

/**
 * 把分钟转为XX天XX小时XX分钟的格式
 * @param n 
 */
export const timeExchange = function(n:number):string {
  let result = "";
  let day = Math.floor(n / (24 * 60));
  if (day >= 1) {
    result += `${day}天`;
  }
  let n2 = n - day * 24 * 60;
  let hour = Math.floor(n2 / 60);
  if (hour >= 1) {
    result += `${hour}小时`;
  }
  let minute = n2 - hour * 60;
  result += `${minute}分`;
  return result;
}
